// pages/personIssue/PersonIssue.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
   data: {
    openId:null,
    isConsent:true,
    startingPlace:'',
    destination:'',
    beginTime: new Date().toLocaleDateString(),
    beginDetailTime:'06:00',
    expectBeginPlace:'',
    userName:'',
    phoneNum:'',
    passengerNum:'',
    shareMark:'',
    
  },
  buttonSubmit(){
    wx:wx.showLoading({title:'正在发布'})

    let data = this.data;
    if (data.startingPlace) {
      if (data.destination.length >= 2) {
        if (data.userName) {
          if (data.phoneNum.length == 11) {
            if (data.passengerNum) {
              if (data.isConsent) {
                wx.request({
                  url: app.globalData.serverUrl+'CarShareMessage/addPassengerCarShareMessage.do',
                  data:data,
                  success(res){
                    if (res.data.state == 1) {
                      wx.hideLoading();
                      wx.showToast({title: '发布成功',icon: 'none'});
                      setTimeout(function(){
                        wx.switchTab({ url: '../index/index'})
                      },1500)
                    }

                  }
                })
              }else{
                wx.showToast({title: '请选择同意拼车平台说明',icon: 'none'})
              }
            }else{
              wx.showToast({title: '填写乘客人数',icon: 'none'})
            }
          }else{
            wx.showToast({title: '填写手机号码',icon: 'none'})
          }
        }else{
          wx.showToast({title: '填写姓名',icon: 'none'})
        }
      }else{
        wx.showToast({title: '填写目的地',icon: 'none'})
      }

    }else{
      wx.showToast({title: '填写出发地',icon: 'none'})
    }

  },

  getGpsFun(e){
    let self = this;
    app.getAddress(function(data) {
      if (e.currentTarget.dataset.lei == 1) {self.setData({startingPlace: data.result.address_component.city})}
       if (e.currentTarget.dataset.lei == 2) {self.setData({expectBeginPlace: data.result.address})}


     })
  },

  inputChangge(e){
    let key = e.currentTarget.dataset.info
    if (key == 'startingPlace') {
      this.setData({"startingPlace" : e.detail.value})
    }
    if (key == 'destination') {
      this.setData({"destination" : e.detail.value})
    }
    if (key == 'beginTime') {
      this.setData({"beginTime" : e.detail.value})
    }
    if (key == 'beginDetailTime') {
      this.setData({"beginDetailTime" : e.detail.value})
    }
    if (key == 'expectBeginPlace') {
      this.setData({"expectBeginPlace" : e.detail.value})
    }
    if (key == 'userName') {
      this.setData({"userName" : e.detail.value})
    }
    if (key == 'phoneNum') {
      this.setData({"phoneNum" : e.detail.value})
    }
    if (key == 'passengerNum') {
      this.setData({"passengerNum" : e.detail.value})
    }
    if (key == 'shareMark') {
      this.setData({"shareMark" : e.detail.value})
    }
    if (key == 'isConsent') {
      this.setData({"isConsent" : !this.data.isConsent})
    }
  },

  
  /**
   * 生命周期函数--监听页面加载
   */
   onLoad: function (options) {
     let self = this;

     if (app.globalData.serverOpenInfo) {
      this.setData({
        openId : app.globalData.serverOpenInfo.openid
      })
    }


  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
   onReady: function () {

   },

  /**
   * 生命周期函数--监听页面显示
   */
   onShow: function () {
     let self = this;
     app.sendUserInfoPage(function(data){
      if (data) {
        self.setData({
         userName:data.userName,
         phoneNum:data.phoneNum,
         userInfo: data,
         hasUserInfo: true
       })
      }
    })


   },

  /**
   * 生命周期函数--监听页面隐藏
   */
   onHide: function () {

   },

  /**
   * 生命周期函数--监听页面卸载
   */
   onUnload: function () {

   },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
   onPullDownRefresh: function () {

   },

  /**
   * 页面上拉触底事件的处理函数
   */
   onReachBottom: function () {

   },

  /**
   * 用户点击右上角分享
   */
   onShareAppMessage: function () {

   }
 })